<template>
	<div>
		<div class="box">
			<ACollapse
				v-if="details.carSourceType !== '2'"
				title="上牌"
				:open="true"
				style="width: 100%">
				<License ref="License"></License>
			</ACollapse>
			<ACollapse
				v-if="details.carSourceType == '2'"
				title="车辆"
				:open="true"
				style="width: 100%">
				<Car
					ref="Car"
					@initInputState="initInputState"
					@initCalcData="initCalcData"
					@getRefittedList="getRefittedList"
					@setInsuranceCarvesselCurrentAmount="setInsuranceCarvesselCurrentAmount"></Car>
			</ACollapse>
			<ACollapse title="车型" :open="true" style="width: 100%" v-else>
				<CarType
					ref="CarType"
					@initInputState="initInputState"
					@initCalcData="initCalcData"
					@getRefittedList="getRefittedList"
					@setInsuranceCarvesselCurrentAmount="
						setInsuranceCarvesselCurrentAmount
					"></CarType>
			</ACollapse>

			<ACollapse title="保险费用" :open="true" style="width: 100%">
				<InsurancePrice ref="InsurancePrice"></InsurancePrice>
			</ACollapse>
			<ACollapse
				v-if="details.carSourceType == '1' || details.carSourceType == '3'"
				title="维保费用"
				:open="true"
				style="width: 100%">
				<template #title>
					<div class="title">
						<div class="title-content">维保</div>
						<div class="title-price">
							合计金额： ￥{{ A_viewPrice(currentInfoData.maintenanceFee) }}
						</div>
					</div>
				</template>
				<MaintainPrice ref="MaintainPrice"></MaintainPrice>
			</ACollapse>
			<ACollapse
				v-if="details.carSourceType == '1' || details.carSourceType == '3'"
				title="上牌费用"
				:open="true"
				style="width: 100%">
				<LicensePrice ref="LicensePrice"></LicensePrice>
			</ACollapse>
			<ACollapse
				v-if="!(config.businessSource == '1' && details.rentType_raw == '2')"
				title="替车"
				:open="true"
				style="width: 100%">
				<Replace ref="Replace"></Replace>
			</ACollapse>
			<ACollapse title="加装" :open="true" style="width: 100%">
				<template #title>
					<div class="title">
						<div class="title-content">加装</div>
						<div class="title-price">合计金额： ￥{{ A_viewPrice(refittedPrice) }}</div>
					</div>
				</template>
				<Refitted ref="Refitted"></Refitted>
			</ACollapse>
			<ACollapse title="其他" :open="true" style="width: 100%">
				<template #title>
					<div class="title">
						<div class="title-content">其他</div>
						<div class="title-price">合计金额： ￥{{ A_viewPrice(otherPrice) }}</div>
					</div>
				</template>
				<Other ref="Other"></Other>
			</ACollapse>
			<ACollapse
				v-if="details.carSourceType == '3' && details.outsourcingType == '2'"
				title="上游报价"
				:open="true"
				style="width: 100%">
				<upstream ref="upstream"></upstream>
			</ACollapse>
			<ACollapse title="下游报价" :open="true" style="width: 100%">
				<downstream ref="downstream"></downstream>
			</ACollapse>
			<ACollapse v-if="state == 'readonly'" title="报价总览" :open="true" style="width: 100%">
				<PricePreview ref="PricePreview"></PricePreview>
			</ACollapse>
			<ACollapse
				v-if="state == 'readonly'"
				title="财务利润测算"
				:open="true"
				style="width: 100%">
				<PriceForecast ref="PriceForecast"></PriceForecast>
			</ACollapse>
			<ACollapse v-if="state == 'readonly'" title="TML" :open="true" style="width: 100%">
				<CollectTable ref="CollectTable"></CollectTable>
			</ACollapse>
		</div>
	</div>
</template>

<script>
	import * as apis from '@/api/quota/apply/api.js';
	import * as utils from '@/pages/quota/libs/utils.js';
	import Car from '@/pages/quota/apply/coms/car/index.vue';
	import CarType from '@/pages/quota/apply/coms/cartype/index.vue';
	import InsurancePrice from '@/pages/quota/apply/coms/insurancePrice/index.vue';
	import MaintainPrice from '@/pages/quota/apply/coms/maintainPrice/index.vue';
	import LicensePrice from '@/pages/quota/apply/coms/licensePrice/index.vue';
	import License from '@/pages/quota/apply/coms/license/index.vue';
	import Replace from '@/pages/quota/apply/coms/replace/index.vue';
	import Refitted from '@/pages/quota/apply/coms/refitted/index.vue';
	import Other from '@/pages/quota/apply/coms/other/index.vue';
	import Upstream from '@/pages/quota/apply/coms/upstream/index.vue';
	import Downstream from '@/pages/quota/apply/coms/downstream/index.vue';
	import PricePreview from '@/pages/quota/apply/coms/pricePreview/index.vue';
	import PriceForecast from '@/pages/quota/apply/coms/priceForecast/index.vue';
	import CollectTable from '@/pages/quota/apply/coms/collectTable/index.vue';

	export default {
		name: '',
		components: {
			Car,
			CarType,
			License,
			Replace,
			InsurancePrice,
			MaintainPrice,
			LicensePrice,
			Refitted,
			Other,
			Upstream,
			Downstream,
			PricePreview,
			PriceForecast,
			CollectTable,
		},
		props: {
			index: {
				required: true,
				type: Number,
			},
		},
		data() {
			return {
				itemDictList: {
					refittedList: [{ decorationName: 1, decorationName: 1, price: 1 }],
				},
			};
		},
		inject: ['details_provide', 'config_provide', 'state_provide'],
		provide() {
			return {
				index_provide: () => this.index,
				itemDictList_provide: () => this.itemDictList,
			};
		},
		computed: {
			details() {
				return this.details_provide();
			},
			config() {
				return this.config_provide();
			},
			state() {
				return this.state_provide();
			},
			currentInfoData() {
				return this.details.productList?.[this.index] ?? {};
			},
			firstInfoData() {
				return this.details.productList?.[0] ?? {};
			},
			refittedPrice() {
				let money = 0;
				this.currentInfoData?.attachedDecorationList?.map?.(item => {
					if (item.decorationCount && item.decorationPrice) {
						let itemMoney = utils.toNumberRide(
							item.decorationCount,
							item.decorationPrice,
						);
						if (Number.isFinite(itemMoney)) {
							money = utils.toNumberAdd(money, itemMoney);
						}
					}
				});
				return money;
			},
			otherPrice() {
				let money = 0;
				this.currentInfoData?.feeList?.map?.(item => {
					if (item.feeCount && item.feeAmount) {
						let itemMoney = utils.toNumberRide(item.feeCount, item.feeAmount);
						if (Number.isFinite(itemMoney)) {
							money = utils.toNumberAdd(money, itemMoney);
						}
					}
				});
				return money;
			},
		},
		created() {},
		mounted() {},
		methods: {
			closeACollapse() {
				this.$children?.map(item => {
					if (item.$options.name === 'ACollapse') {
						item?.closeStatus?.();
					}
				});
			},
			openACollapse() {
				this.$children?.map(item => {
					if (item.$options.name === 'ACollapse') {
						item?.openStatus?.();
					}
				});
			},
			changeACollapse(status = true) {
				this.$children?.map(item => {
					if (item.$options.name === 'ACollapse') {
						item?.changeStatus?.(status);
					}
				});
			},
			setInsuranceCarvesselCurrentAmount() {
				this.$refs.InsurancePrice.setInsuranceCarvesselCurrentAmount();
			},
			getRefittedList() {
				this.$refs.Refitted.getRefittedList();
			},
			calc(type) {
				return new Promise((resolve, reject) => {
					if (
						this.details.carSourceType == '2' &&
						this.Empty(this.currentInfoData?.plan?.carSurplusAppraisal)
					) {
						uni.showModal({
							content: '请先输入当期残值',
							showCancel: false,
						});
						reject();
						return;
					}

					if (
						this.details?.carType == '2' &&
						this.details?.carSourceType == '1' &&
						this.details?.rentType_raw == '1'
					) {
						if (this.Empty(this.currentInfoData?.plan?.finalEvaluationPrice)) {
							uni.showModal({
								content: '请先输入到期评估价',
								showCancel: false,
							});
							reject();
							return;
						}
					}
					uni.showLoading({ mask: true, title: '测算中...' });

					let params = this.getComputeParams(this.details, this.currentInfoData);
					this.setQuoterCalcParam(params);
					apis.Calc(params)
						.then(res => {
							if (res.code == 200) {
								// uni.hideLoading();
								if (type == 'single') {
									this.$nextTick(() => {
										uni.showToast({
											mask: true,
											title: '测算成功',
										});
									});
								}
								let data = res.data.calcItemList[0];
								this.$nextTick(() => {
									this.setComputeResult(data, params.calcItemList[0]);
								});

								resolve(true);
							} else {
								throw new Error(res);
							}
						})
						.catch(err => {
							uni.showModal({
								content: err.msg || '测算错误',
								showCancel: false,
							});
							// resolve(false);
							uni.hideLoading();

							reject(err);
						})
						.finally(() => {});
				});
			},
			// 设置测算结果
			setComputeResult(data, params) {
				let that = this;
				let productListItem = this.firstInfoData;
				let planPaymentFrequencyTypeList = [
					{
						key1: '0',
						key2: '1',
					},
					{
						key1: '1',
						key2: '3',
					},
					{
						key1: '2',
						key2: '6',
					},
					{
						key1: '3',
						key2: '12',
					},
				];

				this.$set(
					this.currentInfoData.plan,
					'carModelId',
					this.setRowOrUndefined(data.carModelId),
				);
				// 销售价格、采购价
				this.$set(
					this.currentInfoData.plan,
					'purchasePrice',
					this.setRowOrUndefined(data.salePrice),
				);

				this.$set(
					this.currentInfoData.plan,
					'planTenancyType',
					this.setRowOrUndefined(data.leaseTerm),
				);

				this.$set(productListItem, 'maintenanceAnnualMileageKey', data.annualKilometers);

				this.$set(this.currentInfoData.plan, 'operationType', data.vehicleUse?.toString());

				// 上牌城市
				this.$set(this.currentInfoData, 'carCalcCityKey', data.registrationCityId);

				// vehicleUseCityId: "", // 用车城市
				this.currentInfoData.carLicensePrice = this.setRowOrUndefined(data.registrationFee);
				this.$set(
					this.currentInfoData,
					'carLicensePrice',
					this.setRowOrUndefined(data.registrationFee),
				);

				this.$set(
					this.currentInfoData,
					'carLicensePrice_calc',
					this.setRowOrUndefined(data.registrationFee),
				);

				this.$set(
					this.currentInfoData,
					'carLicenseCityPrice',
					this.setRowOrUndefined(data.restrictedLicenseFee),
				);
				// this.formData.plan.carGuidePrice = data.salePrice; // 销售价格
				// this.formData.plan.planTimeStart = this.A_formatTime(
				//     data.leaseStartDate,
				//     1
				// );

				this.$set(
					this.currentInfoData.plan,
					'planPaymentMethodType',
					data.paymentTimeMethod,
				);
				console.log(this.setRowOrUndefined(data.firstInstallmentRent));

				this.$set(
					this.currentInfoData.plan,
					'planFirstRent',
					this.setRowOrUndefined(data.firstInstallmentRent),
				);
				this.$set(
					this.currentInfoData.plan,
					'planViolationCashdeposit',
					this.setRowOrUndefined(data.violationDeposit),
				);
				this.$set(
					this.currentInfoData.plan,
					'planRent',
					this.setRowOrUndefined(data.periodicRent),
				);

				this.$set(
					this.currentInfoData.plan,
					'planPricingIrr',
					utils.toNumberRide(data?.pricingIrr, 100),
				);

				this.$set(
					this.currentInfoData,
					'substituteMaintenanceRent',
					this.setRowOrUndefined(data?.alternativeCarCalcResult?.alternativeCarFee),
				);

				this.$set(
					this.currentInfoData,
					'substituteControlRent',
					this.setRowOrUndefined(
						data?.alternativeCarCalcResult?.restrictedSubstituteCarFee,
					),
				);
				// 交强险测算金额(年)

				this.$set(
					this.currentInfoData,
					'insuranceCompulsoryQuondamAmount',
					this.setRowOrUndefined(
						data?.insuranceCalcResult?.calcAnnualCompulsoryInsurance,
					),
				);
				// if (!this.getIn()) {
				//     this.formData.insuranceCompulsoryQuondamAmount =
				//         this.setRowOrUndefined(
				//             data?.insuranceCalcResult?.annualCompulsoryInsurance
				//         ) ?? this.formData.insuranceCompulsoryCurrentAmount;
				// }
				// 本次交强险金额(年)
				this.$set(
					this.currentInfoData,
					'insuranceCompulsoryCurrentAmount',
					this.setRowOrUndefined(data?.insuranceCalcResult?.annualCompulsoryInsurance),
				);
				//车船税测算金额(年)

				this.$set(
					this.currentInfoData,
					'insuranceCarvesselQuondamAmount',
					this.setRowOrUndefined(data?.insuranceCalcResult?.calcAnnualVehicleTax),
				);
				// if (!this.getIn()) {
				//     this.formData.insuranceCarvesselQuondamAmount =
				//         this.setRowOrUndefined(
				//             data?.insuranceCalcResult?.annualVehicleTax
				//         ) ?? this.formData.insuranceCarvesselCurrentAmount;
				// }

				//本次车船税金额(年)

				this.$set(
					this.currentInfoData,
					'insuranceCarvesselCurrentAmount',
					this.setRowOrUndefined(data?.insuranceCalcResult?.annualVehicleTax),
				);
				// 商业险测算金额(年)

				this.$set(
					this.currentInfoData,
					'insuranceCommercialQuondamAmount',
					this.setRowOrUndefined(
						data?.insuranceCalcResult?.calcAnnualCommercialInsurance,
					),
				);
				// if (!this.getIn()) {
				//     this.formData.insuranceCommercialQuondamAmount =
				//         this.setRowOrUndefined(
				//             data?.insuranceCalcResult?.annualCommercialInsurance
				//         ) ?? this.formData.insuranceCommercialCurrentAmount;
				// }

				// 本次商业险金额(年)

				this.$set(
					this.currentInfoData,
					'insuranceCommercialCurrentAmount',
					this.setRowOrUndefined(data?.insuranceCalcResult?.annualCommercialInsurance),
				);
				//购买类型

				this.$set(
					productListItem,
					'insuranceBuyType',
					this.setRowOrUndefined(data?.insuranceCalcResult?.insuranceBuyType),
				);
				//保险公司
				this.$set(
					productListItem,
					'insuranceCompanyKey',
					this.setRowOrUndefined(data?.insuranceCalcResult?.insuranceCompanyId),
				);

				let planPaymentFrequencyType = planPaymentFrequencyTypeList.find(
					e => e.key1 == data.paymentMethod?.toString(),
				)?.key2;
				//支付频率
				this.$set(
					this.currentInfoData.plan,
					'planPaymentFrequencyType',
					planPaymentFrequencyType,
				);
				if (productListItem?.maintenanceType == '1') {
					// 维保费用（月）
					this.$set(
						this.currentInfoData,
						'maintenancePrice',
						data?.maintenanceCalcResult?.monthlyMaintenanceFee,
					);
					// 维保费用合计
					this.$set(
						this.currentInfoData,
						'maintenanceFee',
						data?.maintenanceCalcResult?.totalMaintenanceFee,
					);
				} else {
					this.$set(this.currentInfoData, 'maintenancePrice', undefined);
					this.$set(this.currentInfoData, 'maintenanceFee', undefined);
				}
				if (this.currentInfoData.planConf?.maintenancePrice_state == 'changed') {
					this.$set(this.currentInfoData, 'maintenancePriceQuondam', -1);
				} else {
					this.$set(
						this.currentInfoData,
						'maintenancePriceQuondam',
						data?.maintenanceCalcResult?.monthlyMaintenanceFee,
					);
				}
				// this.currentInfoData.maintenanceMealType =
				//     data?.maintenanceCalcResult?.maintenancePackageId;

				this.currentInfoData?.maintenanceList?.map(item => {
					let e = data?.maintenanceCalcResult?.maintenanceServiceList?.find(
						e =>
							e.maintenanceServiceName?.toString() ==
							item?.maintenanceItemTypeStr?.toString(),
					);
					if (e) {
						this.$set(item, 'maintenanceCount', e.count);
						this.$set(item, 'maintenanceFee', e.maintenanceFee);
					}
				});

				// 投入总额
				this.$set(
					this.currentInfoData.plan,
					'planTotalInvestment',
					data.totalInvestmentByCompany,
				);

				// if (
				//     // this.Empty(this.formData?.plan?.planContractCashdeposit) &&
				//     this.formData?.planConf?.planContractCashdeposit_state !==
				//         "changed" &&
				//     data.contractDeposit == 0
				// ) {
				//     let ratio =
				//         this.config?.quotationProductSchemeRule
				//             ?.contractDepositMinimumRentMonths;

				//     if (this.notEmpty(ratio)) {
				//         console.log("合同保证金倍数：" + ratio);
				//         let planContractCashdeposit = utils.toNumberRide(
				//             data.periodicRent,
				//             ratio
				//         );
				//         this.formData.plan.planContractCashdeposit = isNaN(
				//             planContractCashdeposit
				//         )
				//             ? undefined
				//             : planContractCashdeposit;

				//         this.formData.planConf.planContractCashdeposit_state =
				//             "changed";
				//         this.$emitter.emit(
				//             "clearVaild_downStream",
				//             "planContractCashdeposit"
				//         );
				//     } else {
				//         console.log("没有配置合同保证金倍数");
				//     }
				// } else {
				//     this.formData.plan.planContractCashdeposit =
				//         this.setRowOrUndefined(data.contractDeposit);
				// }

				// 合同保证金
				this.$set(
					this.currentInfoData.plan,
					'planContractCashdeposit',
					this.setRowOrUndefined(data.contractDeposit),
				);
				this.$set(this.currentInfoData, 'carPurchaseTax', data.purchaseTax);

				this.$set(
					this.currentInfoData.plan,
					'planResidual',
					data?.residualValueCalcResult?.residualValue,
				);
				// 残值比例（%）

				this.$set(
					this.currentInfoData,
					'planResidualProportion',
					data?.residualValueCalcResult?.inputResidualValueRate
						? utils.toNumberRide(
								data?.residualValueCalcResult?.inputResidualValueRate,
								100,
						  )
						: undefined,
				);
				// 尾款(残值)
				this.$set(
					this.currentInfoData.plan,
					'planBalancepayment',
					data?.residualValueCalcResult?.residualValue,
				);
				// 当期残值
				if (this.details.carSourceType == '2') {
					this.$set(
						this.currentInfoData.plan,
						'carSurplusAppraisal',
						data?.residualValueCalcResult?.residualValue,
					);
				}
				// 到期评估价
				if (
					this.details?.carType == '2' &&
					this.details?.carSourceType == '1' &&
					this.details?.rentType_raw == '1'
				) {
					this.$set(
						this.currentInfoData.plan,
						'finalEvaluationPrice',
						data?.residualValueCalcResult?.residualValue,
					);
				}
				// GPS费用
				this.$set(this.currentInfoData.plan, 'gpsFee', data.gpsFee);
				//  年检费

				this.$set(this.currentInfoData.plan, 'annualCheckFee', data.annualInspectionFee);
				let totalPrice = this.getTotalPrice(this.currentInfoData);
				if (
					totalPrice !== 0 &&
					totalPrice !== '0' &&
					totalPrice !== '-' &&
					data.firstInstallmentRent !== 0 &&
					data.firstInstallmentRent !== '0' &&
					this.Empty(this.currentInfoData.plan?.planFirstRentProportion)
				) {
					let firstInstallmentRentRatio = utils.toNumberExcept(
						Number(data.firstInstallmentRent),
						totalPrice,
					);

					this.$set(
						this.currentInfoData.plan,
						'planFirstRentProportion',
						utils.toNumberRide(firstInstallmentRentRatio, 100),
					);
				}
				// this.initInputState();
				this.$nextTick(() => {
					this.$forceUpdate();
				});
			},
			setRowOrUndefined(row) {
				if (row === '' || row === null || row === undefined) {
					return undefined;
				} else {
					return row;
				}
			},
			getTotalPrice(row) {
				let p = 0;

				let monthlyRent = utils.toNumberExcept(
					row?.plan?.planRent,
					row?.plan?.planPaymentFrequencyType,
				);
				if (monthlyRent && row?.plan?.planTenancyType) {
					p = utils.toNumberRide(monthlyRent, row?.plan?.planTenancyType) * 1;
				}
				if (this.details.rentType_raw == '1') {
					return p;
				} else {
					let price =
						p +
						(row?.plan?.planBalancepayment * 1 ?? 0) +
						(row?.plan?.planFirstRent * 1 ?? 0);
					return isNaN(price) ? '-' : price;
				}
			},
			setQuoterCalcParam(params) {
				let arr = params ?? this.getComputeParams(this.details);
				if (this.notEmpty(arr)) {
					this.details.quoterCalcParam = JSON.stringify(arr);
				}
			},
			getComputeParams(details, formData) {
				let that = this;
				let list = formData ?? details?.productList;
				return {
					quotationProductSchemeId: details.schemeId,
					customerTypeId: details.customerType,
					calcItemList: that.getComputeParamsBody(list),
				};
			},
			getComputeParamsBody(productList) {
				let list = [];
				let planPaymentFrequencyTypeList = [
					{
						key1: '0',
						key2: '1',
					},
					{
						key1: '1',
						key2: '3',
					},
					{
						key1: '2',
						key2: '6',
					},
					{
						key1: '3',
						key2: '12',
					},
				];
				if (Object.prototype.toString.call(productList) == '[object Array]') {
					list = productList;
				} else if (Object.prototype.toString.call(productList) == '[object Object]') {
					list = [productList];
				}
				let ratio =
					this.config?.quotationProductSchemeRule?.contractDepositMinimumRentMonths;
				let productListItem = this.A_deepClone(this.details?.productList[0]);
				let arr = list?.map(formData => {
					let paymentMethod = planPaymentFrequencyTypeList.find(e => {
						return e.key2 == formData?.plan?.planPaymentFrequencyType?.toString();
					})?.key1;
					let result = {
						seatNumber: formData.plan.carSeating, // 座位数
						paymentMethod, //支付方法
						salePrice: formData.plan.purchasePrice, //原新车采购价
						leaseTerm: formData.plan.planTenancyType, // 租赁期限(月）
						sequenceNumber: formData.sequenceNumber,
						carld: formData.plan.carId,
						count: formData.plan.quantityRequired, //台数
						carCurrentAppraisal: formData.plan.carCurrentAppraisal, //当期评估价
						billingMethod: formData.plan.planBillType, //账单生成方式
						accountPeriod: formData.plan.planPeriod, // 账期
						// 首期租金比例（%）
						firstInstallmentRentalRatio: utils.toNumberExcept(
							formData.plan?.planFirstRentProportion,
							100,
						),
						// ? isNaN(formData.plan?.planFirstRentProportion / 100)
						// 	? null
						// 	: formData.plan?.planFirstRentProportion / 100
						// : null,
						// 保证金比例（%）
						planCashdepositProportion: utils.toNumberExcept(
							formData.plan?.planCashdepositProportion,
							100,
						),
						// ? isNaN(formData.plan?.planCashdepositProportion / 100)
						// 	? null
						// 	: formData.plan?.planCashdepositProportion / 100
						// : null,
						carModelId: formData.plan.carModelId, //车型id
						// 年行驶公里数 #
						annualKilometers: productListItem.maintenanceAnnualMileageKey,
						vehicleUse: formData.plan.operationType, //车辆使用性质
						registrationCityId: formData.carCalcCityKey,
						vehicleUseCityId: formData.carCalcCityKey, // 用车城市
						// 上牌费（台）
						registrationFee: this.getChangedVal(formData, 'carLicensePrice', formData),

						// 限牌城市牌照费（台）
						restrictedLicenseFee: this.getChangedVal(
							formData,
							'carLicenseCityPrice',
							formData,
						),
						gpsFee: this.getChangedVal(formData.plan, 'gpsFee', formData),
						// 预计起租日期
						leaseStartDate: formData?.plan?.planTimeStart
							? this.A_formatTime(formData.plan.planTimeStart, 0)
							: null,
						// 支付时间
						paymentTimeMethod: formData.plan.planPaymentMethodType,
						// 首期租金
						firstInstallmentRent: this.getChangedVal(
							formData.plan,
							'planFirstRent',
							formData,
						),
						// 合同保证金
						contractDeposit: this.getChangedVal(
							formData.plan,
							'planContractCashdeposit',
							formData,
						),
						// 违章保证金
						violationDeposit: this.getChangedVal(
							formData.plan,
							'planViolationCashdeposit',
							formData,
						),
						periodicRent: formData.plan?.planRent, //每期租金
						// APR（%）
						pricingIrr: utils.toNumberExcept(formData.plan?.planPricingIrr, 100),
						// 倍率
						contractDepositMinimumRentMonths: ratio,
						// 残值
						residualValueParam: {
							inputResidualValueRate: formData.plan?.planResidualProportion
								? isNaN(formData.plan?.planResidualProportion / 100)
									? null
									: formData.plan?.planResidualProportion / 100
								: null,
							residualValue:
								// 当期残值
								this.details.carSourceType == '2'
									? formData.plan?.carSurplusAppraisal
									: this.details?.carType == '2' &&
									  this.details?.carSourceType == '1' &&
									  this.details?.rentType_raw == '1'
									? this.getChangedVal(
											formData?.plan,
											'finalEvaluationPrice',
											formData,
									  )
									: this.getChangedVal(
											formData?.plan,
											'planBalancepayment',
											formData,
									  ),
						},
						logisticFee: formData.plan?.logisticFee, //物流费
						warehouseOutCharge: formData.plan?.warehouseOutCharge, // 出库费
						alternativeCarParam: {
							alternativeCarLevelId:
								formData.substituteMaintenanceLevel == '1'
									? formData.substituteMaintenanceLevelType
									: null,
							enableRestrictedSubstituteCar:
								formData.substituteControlLevelType == '1'
									? 1
									: formData.substituteControlLevelType == '2'
									? 0
									: null,
							// 维保替代车价格（月）
							alternativeCarFee: this.getChangedVal(
								formData,
								'substituteMaintenanceRent',
								formData,
							),
							// 限行替代车价格（月）
							restrictedSubstituteCarFee: this.getChangedVal(
								formData,
								'substituteControlRent',
								formData,
							),
						},
						finalEvaluationPrice:
							this.details?.carType == '2' &&
							this.details?.carSourceType == '1' &&
							this.details?.rentType_raw == '1'
								? this.getChangedVal(
										formData?.plan,
										'finalEvaluationPrice',
										formData,
								  )
								: undefined,
						decorationParam: {
							totalDecorationPrice: null,
							decorationList: formData?.attachedDecorationList
								?.map(item => {
									if (
										this.notEmpty(item.decorationVal) &&
										this.notEmpty(item.decorationCount) &&
										this.notEmpty(item.decorationPrice)
									) {
										return {
											decorationName: item.decorationVal,
											count: item.decorationCount,
											price: Number(item.decorationPrice),
										};
									}
								})
								?.filter(item => this.notEmpty(item)),
						},
						otherParam: {
							totalOtherPrice: null,
							otherItemList: formData?.feeList
								?.map(item => {
									if (
										this.notEmpty(item.feeVal) &&
										this.notEmpty(item.feeCount) &&
										this.notEmpty(item.feeAmount)
									)
										return {
											otherItemName: item.feeVal,
											count: item.feeCount,
											price: Number(item.feeAmount),
										};
								})
								?.filter(item => this.notEmpty(item)),
						},
						insuranceParam: {
							// 本次交强险金额
							annualCompulsoryInsurance: this.getIn(formData)
								? formData.insuranceCompulsoryCurrentAmount
								: undefined,
							// annualCompulsoryInsurance: this.getChangedVal(
							//     formData,
							//     "insuranceCompulsoryCurrentAmount"
							// ),
							// 本次车船税金额
							annualVehicleTax: this.getIn(formData)
								? formData.insuranceCarvesselCurrentAmount
								: undefined,
							// annualVehicleTax: this.getChangedVal(
							//     formData,
							//     "insuranceCarvesselCurrentAmount"
							// ),
							// 本次商业险金额
							annualCommercialInsurance: this.getIn(formData)
								? formData.insuranceCommercialCurrentAmount
								: undefined,
							// annualCommercialInsurance: this.getChangedVal(

							//     formData,
							//     "insuranceCommercialCurrentAmount"
							// ),
							//购买类型
							insuranceBuyType: productListItem.insuranceBuyType,
							// 保险公司
							insuranceCompanyId: productListItem.insuranceCompanyKey,
							// 保险列表
							insuranceItemList: productListItem?.insuranceList
								?.map(item => {
									if (this.notEmpty(item.insuranceItemNameVal)) {
										return {
											isInsured: item.selectedType == '1' ? '1' : '0',
											insuranceItemId: item.insuranceItemNameKey,
											insuranceItemName: item.insuranceItemNameVal,
											coverageAmount: item.sumInsuredVal,
										};
									}
								})
								?.filter(item => this.notEmpty(item)),
						},

						modelSeriesCategory: formData.plan?.carSeriesTypeKey, // 车辆分类
						maintenanceParam: {
							maintenanceAdjustmentFactor: formData.plan?.carSeriesTypeVal, // 车辆系数
							//是否包含维保
							includeMaintenance:
								productListItem.maintenanceType == '1'
									? 1
									: productListItem.maintenanceType == '2'
									? 0
									: null,
							//维保套餐
							maintenancePackageId:
								this.config.businessSource == '2'
									? productListItem.maintenanceMealType
									: null,
							//供应商
							maintenanceSupplierType:
								this.config.businessSource == '1'
									? productListItem.maintenanceSupplierId == 1
										? 1
										: productListItem.maintenanceSupplierId == 2
										? 2
										: null
									: null,
							// 维保费用（月）
							monthlyMaintenanceFee: this.getChangedVal(
								formData,
								'maintenancePrice',
								formData,
							),
						},
					};
					this.initDeep(result);
					return result;
				});
				return arr;
			},
			// 保险是否被修改
			getIn(productListItem) {
				if (productListItem.plan.isGreen == 1) {
					if (
						this.Empty(productListItem?.insuranceCompulsoryCurrentAmount) &&
						this.Empty(productListItem?.insuranceCommercialCurrentAmount)
					) {
						return false;
					}
				} else {
					if (
						this.Empty(productListItem?.insuranceCompulsoryCurrentAmount) &&
						this.Empty(productListItem?.insuranceCarvesselCurrentAmount) &&
						this.Empty(productListItem?.insuranceCommercialCurrentAmount)
					) {
						return false;
					}
				}
				if (
					productListItem?.planConf?.insuranceCompulsoryCurrentAmount_state ==
						'changed' ||
					productListItem?.planConf?.insuranceCarvesselCurrentAmount_state == 'changed' ||
					productListItem?.planConf?.insuranceCommercialCurrentAmount_state == 'changed'
				) {
					return true;
				}
			},
			getChangedVal(data, property, formData) {
				if (formData?.planConf?.[`${property}_state`] == 'changed') {
					return data?.[`${property}`];
				} else {
					return undefined;
				}
			},
			initDeep(obj) {
				if (typeof obj !== 'object') return;
				for (const key in obj) {
					if (Object.hasOwnProperty.call(obj, key)) {
						let element = obj[key];
						if (typeof element == 'object') {
							this.initDeep(element);
						} else {
							if (
								element === null ||
								element === undefined ||
								element === '' ||
								element === -1
							) {
								obj[key] = null;
							}
						}
					}
				}
			},

			initCalcData() {
				let formData = this.currentInfoData;
				// 上牌费（台）
				formData.carLicensePrice = undefined;
				// 限牌城市牌照费（台）
				formData.carLicenseCityPrice = undefined;
				// 维保替代车价格（月）
				formData.substituteMaintenanceRent = undefined;
				// 限行替代车价格（月）
				formData.substituteControlRent = undefined;

				// 首期租金
				formData.plan.planFirstRent = undefined;
				// 合同保证金
				formData.plan.planContractCashdeposit = undefined;
				// 违章保证金
				formData.plan.planViolationCashdeposit = undefined;
				// 尾款
				formData.plan.planBalancepayment = undefined;
				// 当期残值
				if (this.details.carSourceType == '2') {
					formData.plan.carSurplusAppraisal = undefined;
				}
				// 本次交强险金额(年)
				formData.insuranceCompulsoryCurrentAmount = undefined;
				// 本次车船税金额(年)
				formData.insuranceCarvesselCurrentAmount = undefined;
				// 本次商业险金额(年)
				formData.insuranceCommercialCurrentAmount = undefined;

				// 交强险测算金额(年)
				formData.insuranceCompulsoryQuondamAmount = undefined;
				// 车船税测算金额(年)
				formData.insuranceCarvesselQuondamAmount = undefined;
				// 商业险测算金额(年)
				formData.insuranceCommercialQuondamAmount = undefined;
				// 月租金
				formData.plan.planRent = undefined;

				formData.plan.gpsFee = undefined;
			},
			initInputState() {
				let formData = this.currentInfoData;
				formData.planConf = {};
				// // 上牌费（台）
				// formData.carLicensePrice_state = "";
				// // 限牌城市牌照费（台）
				// formData.carLicenseCityPrice_state = "";
				// // 维保替代车价格（月）
				// formData.substituteMaintenanceRent_state = "";
				// // 限行替代车价格（月）
				// formData.substituteControlRent_state = "";

				// // 首期租金
				// formData.plan.planFirstRent_state = "";
				// // 合同保证金
				// formData.plan.planContractCashdeposit_state = "";
				// // 违章保证金
				// formData.plan.planViolationCashdeposit_state = "";
				// // 尾款
				// formData.plan.planBalancepayment_state = "";

				// // 本次交强险金额(年)
				// formData.insuranceCompulsoryCurrentAmount_state = "";
				// // 本次车船税金额(年)
				// formData.insuranceCarvesselCurrentAmount_state = "";
				// // 本次商业险金额(年)
				// formData.insuranceCommercialCurrentAmount_state = "";

				// // 月租金
				// formData.plan.planRent_state = "";
			},
		},
	};
</script>

<style lang="scss" scoped>
	.box {
		padding: 0 15rpx;
	}
	.title {
		display: flex;
		.title-content {
			font-weight: bold;
			padding-right: 15rpx;
		}
		.title-price {
			font-size: 11px;
			display: flex;
			align-items: flex-end;
		}
	}
</style>
